<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>

description("This tests the constructor for the ErrorEvent DOM class.");

// No initializer is passed.
shouldBe("new ErrorEvent('eventType').bubbles", "false");
shouldBe("new ErrorEvent('eventType').cancelable", "false");
shouldBeEqualToString("new ErrorEvent('eventType').message", "");
shouldBeEqualToString("new ErrorEvent('eventType').filename", "");
shouldBe("new ErrorEvent('eventType').lineno", "0");

// bubbles is passed.
shouldBe("new ErrorEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new ErrorEvent('eventType', { bubbles: true }).bubbles", "true");

// cancelable is passed.
shouldBe("new ErrorEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new ErrorEvent('eventType', { cancelable: true }).cancelable", "true");

// message or filename is passed.
["message", "filename"].forEach(function (attr) {
    // Strings.
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": 'melancholy' })." + attr, "melancholy");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": '' })." + attr, "");

    // Non-strings.
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": undefined })." + attr, "");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": null })." + attr, "null");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": false })." + attr, "false");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": true })." + attr, "true");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": 12345 })." + attr, "12345");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "18446744073709552000");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": NaN })." + attr, "NaN");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": [] })." + attr, "");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": [1, 2, 3] })." + attr, "1,2,3");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": {melancholy: 12345} })." + attr, "[object Object]");
    shouldBeEqualToString("new ErrorEvent('eventType', { " + attr + ": {valueOf: function () { return 'melancholy'; } } })." + attr, "[object Object]");
});

// lineno is passed.
// numbers within the unsigned long range.
shouldBe("new ErrorEvent('eventType', { lineno: 0 }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: 1 }).lineno", "1");
shouldBe("new ErrorEvent('eventType', { lineno: 4294967294 }).lineno", "4294967294");
shouldBe("new ErrorEvent('eventType', { lineno: 4294967295 }).lineno", "4294967295");

// numbers out of the unsigned long range.
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new ErrorEvent('eventType', { lineno: 9007199254740991 }).lineno", "4294967295");
// 2^{64}-1
shouldBe("new ErrorEvent('eventType', { lineno: 18446744073709551615 }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: 12345678901234567890 }).lineno", "3944679424");
shouldBe("new ErrorEvent('eventType', { lineno: -1 }).lineno", "4294967295");
shouldBe("new ErrorEvent('eventType', { lineno: 123.45 }).lineno", "123");
shouldBe("new ErrorEvent('eventType', { lineno: NaN }).lineno", "0");

// Non-numeric values.
shouldBe("new ErrorEvent('eventType', { lineno: undefined }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: null }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: '' }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: '12345' }).lineno", "12345");
shouldBe("new ErrorEvent('eventType', { lineno: '12345a' }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: 'abc' }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: [] }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: [12345] }).lineno", "12345");
shouldBe("new ErrorEvent('eventType', { lineno: [12345, 67890] }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: {} }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: {moemoe: 12345} }).lineno", "0");
shouldBe("new ErrorEvent('eventType', { lineno: {valueOf: function () { return 12345; }} }).lineno", "12345");

// colno is passed.
// numbers within the unsigned long range.
shouldBe("new ErrorEvent('eventType', { colno: 0 }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: 1 }).colno", "1");
shouldBe("new ErrorEvent('eventType', { colno: 4294967294 }).colno", "4294967294");
shouldBe("new ErrorEvent('eventType', { colno: 4294967295 }).colno", "4294967295");

// numbers out of the unsigned long range.
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new ErrorEvent('eventType', { colno: 9007199254740991 }).colno", "4294967295");
// 2^{64}-1
shouldBe("new ErrorEvent('eventType', { colno: 18446744073709551615 }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: 12345678901234567890 }).colno", "3944679424");
shouldBe("new ErrorEvent('eventType', { colno: -1 }).colno", "4294967295");
shouldBe("new ErrorEvent('eventType', { colno: 123.45 }).colno", "123");
shouldBe("new ErrorEvent('eventType', { colno: NaN }).colno", "0");

// Non-numeric values.
shouldBe("new ErrorEvent('eventType', { colno: undefined }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: null }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: '' }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: '12345' }).colno", "12345");
shouldBe("new ErrorEvent('eventType', { colno: '12345a' }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: 'abc' }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: [] }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: [12345] }).colno", "12345");
shouldBe("new ErrorEvent('eventType', { colno: [12345, 67890] }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: {} }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: {moemoe: 12345} }).colno", "0");
shouldBe("new ErrorEvent('eventType', { colno: {valueOf: function () { return 12345; }} }).colno", "12345");

// error is passed.
shouldBe("new ErrorEvent('eventType', { error: { moemoe: 12345 } }).error.moemoe", "12345");
shouldBeEqualToString("new ErrorEvent('eventType', { error: { message: 'Message' } }).error.message", "Message");

// All initializers are passed.
shouldBe("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).bubbles", "true");
shouldBe("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).cancelable", "true");
shouldBeEqualToString("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).message", "sakuranbo");
shouldBeEqualToString("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).filename", "amaenbo");
shouldBe("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).lineno", "12345");
shouldBe("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).colno", "23456");
shouldBeEqualToString("new ErrorEvent('eventType', { bubbles: true, cancelable: true, message: 'sakuranbo', filename: 'amaenbo', lineno: 12345, colno: 23456, error: { message: 'hi' } }).error.message", "hi");
</script>
</body>
</html>
